﻿using MediatR;
using System.CJL.API.Application.Command.ProcessCommand;
using System.CJL.Infrstructre.Interface;

namespace System.CJL.API.Application.CommandHanlder.ProcessCommandHanler
{
	public class ProcessDeletePiCommandHandler:IRequestHandler<ProcessDeletePiCommand, int>
	{
		IProcessRepository _repository;
        public ProcessDeletePiCommandHandler(IProcessRepository repository)
        {
			_repository=repository;

		}

		public async Task<int> Handle(ProcessDeletePiCommand request, CancellationToken cancellationToken)
		{
			var list = (await _repository.GetAll()).Where(x => request.id.Contains(x.ProcessId));
			foreach (var item in list)
			{
				item.IsDelete = true;
				item.DelectTime = DateTime.Now.ToUniversalTime();
				item.DelectName = "李四";
				await _repository.UpdateAsync(item);
			}
			return 1;
		}
	}
}
